<template>
	<view class="groupComboDetails">
		<view class="goods" @click="jump('group_view', info.product_id+'&merchantId='+info.merchant_id)">
			<view class="left">
				<image :src="info.product_img" mode="aspectFill"></image>
				<view class="state">
					{{info.status_name}}
				</view>
			</view>
			<view class="right">
				<text class="oneline">{{info.product_name}}</text>
				<text>{{info.product_price > 0 ? '¥'+info.product_price : ''}}{{info.product_price > 0 && info.product_point > 0 ? ' + ' : ''}}{{info.product_point > 0 ? info.product_point+'积分' : ''}}</text>
				<text>有效期至{{info.end_time}}</text>
				<text>店铺：{{info.merchant_title}}</text>
			</view>
		</view>
		<view class="code" v-if="info.status == 5 || info.status == 6">
			<view class="code_img">
				<image :src="info.exchange_code_img" mode="aspectFill"></image>
			</view>
			<view class="code_txt">兑换码：{{info.exchange_code}}</view>
		</view>
		<view class="info">
			<view class="line">订单信息：</view>
			<view class="line">订单号：{{info.order_sn}}</view>
			<view class="line">状态：{{info.status_name}}</view>
			<!-- <view class="line">手机号：137****7070 </view> -->
			<view class="line">付款时间：{{info.create_time}}</view>
		</view>
		<view class="bot" v-if="info.button_item != ''"  @click="operate(info.button_item.btype)">{{info.button_item.bname}}</view>
		<uni-popup ref="popup" type="bottom">
			<view class="pay_type">
				<image @click="close" class="close" src="http://hdsq.aoorange.cn/attachment/xcx/icon/close.png" mode="aspectFill"></image>
				<view class="title">支付详情</view>
				<view class="line2" v-if="info.product_point > 0">
					<text>应付积分</text>
					<text>{{info.product_point}}</text>
				</view>
				<view class="line2" v-if="info.product_price > 0">
					<text>应付金额</text>
					<text>¥ {{info.product_price}}</text>
				</view>
				<view class="line2" v-if="info.product_price > 0">
					<text>在线微信支付</text>
					<image src="http://hdsq.aoorange.cn/attachment/xcx/icon/icon37.png" mode="aspectFill"></image>
				</view>
				<view class="pay_bot" @click="wechatPay()">确认支付</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import serve from '../../static/request.js';
	import storage from '../../static/appkey.js';
	import common from '../../static/jump.js';
	export default {
		data() {
			return {
				id:0,
				info:{},
			}
		},
		methods: {
			getInfo() {
				var self = this;
				serve.request({
					url: '/member/merchant-order/group-view',
					data: {
						appkey: uni.getStorageSync('appkey'),
						'access-token': uni.getStorageSync('access-token'),
						id: self.id,
					}
				})
				.then(res => {
					self.info = res.data;
				});
			},
			operate(type) {
				var self = this;
				if(type == 'pay') {
					self.$refs.popup.open();
					return ;
				}
				if(type == 'refund') {
					uni.showModal({
					    title: '提示',
					    content: '您确定申请退款吗',
					    success: function (res) {
					        if (res.confirm) {
					            serve
					            	.request({
					            		url: '/member/merchant-order/refund',
					            		data:{
											appkey: uni.getStorageSync('appkey'),
											'access-token': uni.getStorageSync('access-token'),
											id:self.id,
										}
					            	})
					            	.then(res => {
										uni.showToast({
											title:res.message,
											icon: 'none'
										});
					            		if(res.code == 200) {
											self.getInfo();
					            		} 
					            	});
					        } 
					    }
					});
					return ;
				}
			},
			close() {
				this.$refs.popup.close();
			},
			wechatPay() {
				this.paySuccess(this.id, 'user_money');
				return ;
				if(this.info.is_pay == 0) {
					uni.showModal({
						title : '温馨提示',
						content : '积分不足，无法支付',
						showCancel:false
					});
					return;
				}
				var self = this;
				serve
					.request({
						url: '/order/pay/wechat',
						data:{
							appkey: uni.getStorageSync('appkey'),
							'access-token': uni.getStorageSync('access-token'),
							data_id:self.id,
							data_type : 'group_pay'
						}
					})
					.then(res => {
						if(res.code != 200) {
							uni.showToast({
								title:res.message,
								icon: 'none'
							});
							return ;
						}
						uni.requestPayment({
							provider: 'wxpay',
							timeStamp: res.data.timeStamp,
							nonceStr: res.data.nonceStr,
							package: res.data.package,
							signType: res.data.signType,
							paySign: res.data.paySign,
							success: function (res) {
								self.getInfo();
								return ;
							},
							fail: function (err) {
								uni.showToast({
									title: '放弃支付',
									icon: 'none'
								});
								// common.jump('success', 'type=group&id='+operateId);
								// self.paySuccess(self.pay_id, 'wechat');
								return ;
							}
						});
						self.close();
					});
				return ;
			},
			paySuccess(operateId, payType) {
				var self = this;
				serve
					.request({
						url: '/marketing/group-purchase/pay',
						data:{
							appkey: uni.getStorageSync('appkey'),
							'access-token': uni.getStorageSync('access-token'),
							id:operateId,
							pay_type: payType
						}
					})
					.then(res => {
						uni.showToast({
							title:res.message,
							icon: 'none'
						});
						if(res.code == 200) {
							self.getInfo();
							self.close();
						} 
						return ;
					});
				return ;
			},
			jump(jump_type, jump_link){
				common.jump(jump_type, jump_link);
			}
		},
		onLoad(options) {
			this.id = options.id || 0;
			if(this.id == 0) {
				uni.showToast({
					title: "错误的访问方式",
					icon : 'none',
					success:function(){ 
						setTimeout(function () { 
							common.jump('my_spending_record')
						}, 2000) 
					} 
				});
				return;
			}
		},
		onShow() {
			this.getInfo();
		},
		onPullDownRefresh() {
			this.getInfo();
		}
	}
</script>

<style scoped lang="scss">
	.groupComboDetails {
		padding-bottom: 186rpx;
		.goods {
			box-sizing: border-box;
			padding: 48rpx 30rpx;
			display: flex;
			position: relative;

			.left {
				position: relative;
				height: 170rpx;

				image {
					width: 170rpx;
					height: 170rpx;
				}

				.state {
					position: absolute;
					bottom: 0rpx;
					color: #FFFFFF;
					font-size: 24rpx;
					text-align: center;
					line-height: 40rpx;
					width: 170rpx;
					height: 40rpx;
					background: rgba(235, 90, 56, 0.9);
				}
			}

			.right {
				display: flex;
				flex-direction: column;
				margin-left: 20rpx;
				justify-content: space-between;


				text:nth-child(1) {
					font-size: 32rpx;
					color:#343434;
					font-weight: bold;
				}

				text:nth-child(2) {
					font-size: 28rpx;
					color: #EB5A38;
					font-weight: bold;
					margin-top: 30rpx;
				}

				text:nth-child(3) {
					color:#666666;
					font-size: 24rpx;
				}
				text:nth-child(4) {
					color: #666666;
					font-size: 24rpx;
				}
			}
		}
        .code{
			width: 100%;
			.code_img{
				margin: 0 auto;
				width: 340rpx;
				height: 340rpx;
				border: 1px solid #EB5A38;
				image{
					width: 300rpx;
					height: 300rpx;
					margin: 20rpx;
				}
			}
			.code_txt{
				width: 100%;
				text-align: center;
				color: #666666;
				font-size: 32rpx;
				padding: 45rpx 0rpx;
				border-bottom: 1rpx #EBECF0 solid;
			}
		}
		.info{
			box-sizing: border-box;
			padding: 47rpx 30rpx;
			font-size: 28rpx;
			color: #9A9A9A;
			.line:nth-child(1){
				color: #343434;
				font-weight: bold;
			}
			.line{
				margin-bottom: 30rpx;
			}
		}
		.bot {
			position: fixed;
			bottom: 0;
			width: 100%;
			height: 100rpx;
			line-height: 100rpx;
			text-align: center;
			color: #9A9A9A;
			background-color: #FFFFFF;
			font-size: 28rpx;
			border-top: 1rpx rgba(0, 0, 0, 0.1) solid;
			box-shadow: 1rpx 1rpx 0rpx 0rpx rgba(0, 0, 0, 0.1)
		}
		.pay_type{
			position: relative;
			width: 100%;
			background: #FFFFFF;
			padding-bottom: 140rpx;
			.close{
				position: absolute;
				width:23rpx;
				height:23rpx;
				right: 40rpx;
				top: 45rpx;
			}
			.title{
				width: 100%;
				text-align: center;
				height: 100rpx;
				line-height: 100rpx;
				font-size: 32rpx;
				border-bottom: 1rpx rgba(251, 251, 253, 1) solid;
			}
			.paypir{
				display: flex;
				justify-content: center;
				flex-direction: column;
				align-items: center;
				padding: 50rpx 0rpx 20rpx;
				font-size: 26rpx;
				text:last-child{
					color: rgba(255, 200, 10, 1);
					font-size: 32rpx;
					font-weight: bold;
					margin-top: 10rpx;
				}
			}
			.line2{
				width: 100%;
				box-sizing: border-box;
				padding: 30rpx;
				display: flex;
				justify-content: space-between;
				font-size: 28rpx;
				border-bottom: 1rpx rgba(251, 251, 253, 1) solid;
				image{
					width: 40rpx;
					height: 40rpx;
				}
			}
			.pay_bot {
			  width: 100%;
			  position: fixed;
			  left: 0;
			  bottom: 0;
			  height: 100rpx;
			  background: rgba(255, 200, 10, 1);
			  color: #fff;
			  font-size: 32rpx;
			  line-height: 100rpx;
			  text-align: center;
			  border-radius: 0;
			  &::after{
				  border: none;
			  }
			}
		}
		
	}
</style>
